<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Jedrzej\Pimpable\PimpableTrait;

class SeckillUser extends Model
{
    use HasFactory;
    use PimpableTrait;
    use SoftDeletes;

    public $searchable = [
        'status',
        'start_at',
        'shop_at',
    ];

    public $statusEnum = [
        'participating' => '进行中',
        'endOfActivitySuccess' => ' 已成功',
        'endOfActivityFail' => '已失败',
    ];

    /**
     * 默认倒序
     */
    protected $defaultSortCriteria = ['id,desc'];

    /**
     * 关联砍价商品模型
     */

    public function storeSeckill()
    {
        return $this->belongsTo(StoreSeckill::class, 'seckill_id', 'id')
            ->select('once_num','price','title','start_time');
    }

    /**
     * 关联用户模型
     */

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id')->select('avatar','nickname','id');
    }

    /**
     * 关联订单模型
     */

    public function order()
    {
        return $this->belongsTo(Order::class, 'id', 'seckill_id')
            ->select('order_number','user_name','pay_time');
    }
}
